# .ide/Dockerfile

FROM cnbcool/default-dev-env:latest

RUN wget https://cnb.cool/rzhangsan/cloud-native-build/-/releases/download/0.0.0/debian12_etc_apt_sources.list.txt && \
    cp debian12_etc_apt_sources.list.txt /etc/apt/sources.list && \
    rm -rf debian12_etc_apt_sources.list.txt

RUN apt update && apt-get update && \
    apt-get install -y \
        git wget curl flex bison gperf tree libudev-dev file \
        python3 python3-pip python3-venv \
        ninja-build ccache \
        libffi-dev libssl-dev \
        dfu-util libusb-1.0-0 \
        gcc build-essential pkg-config cmake clang libclang-dev \
        qemu-system qemu-user \
        libcap2-bin nginx nginx-full nginx-extras rclone \	
        locales && \
    rm -rf /var/lib/apt/lists/*

ENV RUSTUP_DIST_SERVER "https://rsproxy.cn"
ENV RUSTUP_UPDATE_ROOT "https://rsproxy.cn/rustup"

# 安装 rustup
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
    . $HOME/.cargo/env

ENV PATH="/root/.cargo/bin:$PATH"

# rust cargo 换源
RUN wget https://cnb.cool/rzhangsan/cloud-native-build/-/releases/download/0.0.0/source.crates-io && \
    cp source.crates-io /root/.cargo/config && \
    rm -rf source.crates-io

RUN cargo install cargo-binutils axconfig-gen cargo-axplat ostool

RUN setcap cap_net_bind_service=+eip $(which ostool)

COPY ../rust-toolchain.toml ./

RUN rustup show

RUN rustup target add riscv64gc-unknown-none-elf
RUN rustup component add llvm-tools-preview
RUN rustup component add rust-src

RUN wget https://musl.cc/x86_64-linux-musl-cross.tgz && tar zxf x86_64-linux-musl-cross.tgz && rm -rf x86_64-linux-musl-cross.tgz
RUN wget https://musl.cc/aarch64-linux-musl-cross.tgz && tar zxf aarch64-linux-musl-cross.tgz  && rm -rf aarch64-linux-musl-cross.tgz
RUN wget https://musl.cc/riscv64-linux-musl-cross.tgz && tar zxf riscv64-linux-musl-cross.tgz && rm -rf riscv64-linux-musl-cross.tgz

ENV PATH="/x86_64-linux-musl-cross/bin:/aarch64-linux-musl-cross/bin:/riscv64-linux-musl-cross/bin:$PATH"

RUN code-server --install-extension rust-lang.rust-analyzer \
    && code-server --install-extension tamasfe.even-better-toml \
    && code-server --install-extension usernamehw.errorlens \
    && code-server --install-extension chanhx.crabviz

COPY .ide/nginx.conf /etc/nginx/
